home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / AppsToGo / AppsToGo.src / DTS.Draw / DoEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  4.3 KB  |  185 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        DoEvent.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.protos.h"        /* Get the prototypes for application.            */
  27.  
  28. #ifndef __CTLHANDLER__
  29. #include "CtlHandler.h"
  30. #endif
  31.  
  32. #ifndef __DESK__
  33. #include <Desk.h>
  34. #endif
  35.  
  36. #ifndef __DISKINIT__
  37. #include <DiskInit.h>
  38. #endif
  39.  
  40. #ifndef __ERRORS__
  41. #include <Errors.h>
  42. #endif
  43.  
  44. #ifndef __MENUS__
  45. #include <Menus.h>
  46. #endif
  47.  
  48. #ifndef __TEXTEDITCONTROL__
  49. #include "TextEditControl.h"
  50. #endif
  51.  
  52. #ifndef __TOOLUTILS__
  53. #include <ToolUtils.h>
  54. #endif
  55.  
  56. #ifndef __UTILITIES__
  57. #include "Utilities.h"
  58. #endif
  59.  
  60.  
  61.  
  62. /*****************************************************************************/
  63.  
  64.  
  65.  
  66. extern Cursor    *gCursorPtr;    /* See the file Window.c for comments about this global. */
  67.  
  68.  
  69.  
  70. /*****************************************************************************/
  71. /*****************************************************************************/
  72.  
  73.  
  74.  
  75. /* Do the right thing for an event.  Determine what kind of event it is, and
  76. ** call the appropriate routines. */
  77.  
  78. #pragma segment Main
  79. void    DoEvent(EventRecord *event)
  80. {
  81.     WindowPtr    window;
  82.     Point        pt;
  83.     OSErr        err;
  84.     TEHandle    teHndl;
  85.     Rect        rct;
  86.  
  87.     switch(event->what) {
  88.  
  89.         case nullEvent:
  90.             DoIdleTasks(event);
  91.             break;
  92.  
  93.         case mouseDown:
  94.             DoMouseDown(event);            /* Let framework handle mouse downs. */
  95.             break;
  96.  
  97.         case autoKey:
  98.         case keyDown:
  99.             DoKeyDown(event);            /* Let framework handle key events. */
  100.             break;
  101.  
  102.         case activateEvt:
  103.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  104.             DoActivate((WindowPtr)event->message);
  105.             break;
  106.  
  107.         case updateEvt:
  108.             DoUpdate((WindowPtr)event->message);
  109.             break;
  110.  
  111.         case kHighLevelEvent:
  112.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  113.             DoHighLevelEvent(event);
  114.             break;
  115.  
  116.         case osEvt:
  117.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  118.             switch ((event->message >> 24) & 0xFF) {
  119.                     /* Must logical and with 0xFF to get only low byte. */
  120.                     /* High byte of message. */
  121.  
  122.                 case mouseMovedMessage:
  123.                     DoIdleTasks(event);        /* Treat mouseMoved events like NULL events. */
  124.                     break;
  125.  
  126.                 case suspendResumeMessage:
  127.                         /* Suspend/resume is also an activate/deactivate. */
  128.                     gInBackground = !((event->message) & resumeFlag);
  129.                     CTEConvertClipboard((event->message) & convertClipboardFlag, !gInBackground);
  130.                     DoActivate(FrontWindow());
  131.                     HiliteWindows();
  132.                     break;
  133.             }
  134.             break;
  135.  
  136.         case diskEvt:
  137.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  138.             if (HiWord(event->message) != noErr) {
  139.                 SetPt(&pt, kDILeft, kDITop);
  140.                 err = DIBadMount(pt, event->message);
  141.             }        /* It is not a bad idea to at least call DIBadMount in response to */
  142.             break;    /* a diskEvt, so that the user can format a floppy. */
  143.     }
  144.  
  145.     DoCursor();
  146.     DoAdjustMenus();
  147.  
  148.     if (window = CTETargetInfo(&teHndl, &rct)) {
  149.         if (rct.left < -8192)        /* If TextEdit control is in the frame...  */
  150.             BeginFrame(window);        /* Set clipping to the frame area.           */
  151.         else
  152.             BeginContent(window);    /* Else set clipping to the document area. */
  153.         CTEIdle();
  154.         EndContent(window);            /* EndContent can be used to close a BeginFrame. */
  155.     }
  156. }
  157.  
  158.  
  159.  
  160. /*****************************************************************************/
  161.  
  162.  
  163.  
  164. /* •• Called by DTS.Lib..framework. •• */
  165.  
  166. /* This is called when a window is activated or deactivated. */
  167.  
  168. #pragma segment Main
  169. void    DoActivate(WindowPtr window)
  170. {
  171.     NotifyCancel();
  172.  
  173.     if (IsAppWindow(window)) {
  174.         SetPort(window);
  175.         DoCtlActivate(window);
  176.         DoDrawFrame(window, true);            /* Redraw frame for new activate state. */
  177.         BeginContent(window);
  178.         DoDrawControls(window, true);        /* Redraw content scrollbars for new activate state. */
  179.         EndContent(window);
  180.     }
  181. }
  182.  
  183.  
  184.  
  185.